package com.db.patterns.client;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

import cm.db.patterns.commands.Command;

/**
 * @author Rayman
 * 
 * Very simple implementation of like a remote server cache, but used blocking queue for interactions with server
 */
public class RemoteServerCache implements ServerCache {
	private static final long TIMEOUT = 1000;
	
	BlockingQueue<Command> queue;
	public RemoteServerCache(BlockingQueue<Command> queue) {
		this.queue = queue;
	}

	@Override
	public Command getUpdates() {
		try {
			return queue.poll(TIMEOUT, TimeUnit.MILLISECONDS);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return null;
	}
}
